package com.ycsj.common.manager;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;

/**
 * SmartRefreshLayout的通用设置类
 * Created by Administrator on 2018/1/19 0019.
 */

public class SrfManager {

    /*-------------------------------仅仅使用SmartRefreshLayout的下拉刷新功能--------------------------------------------------------------------*/

    /**
     * 仅仅使用SmartRefreshLayout的下拉刷新功能
     *
     * @param srl
     * @param listener
     */
    public static void setSmartByPullListener(SmartRefreshLayout srl, final OnPullRefreshListener listener) {
        if (srl != null) {
            srl.setEnableAutoLoadMore(false);//关闭自动加载更多
            if (null != listener) {
                srl.setEnableRefresh(true);//启用下拉刷新功能
            } else {
                srl.setEnableRefresh(false);//启用下拉刷新功能
            }
            srl.setEnableLoadMore(false);//关闭加载更多功能
            srl.setOnRefreshListener(new com.scwang.smartrefresh.layout.listener.OnRefreshListener() {
                @Override
                public void onRefresh(RefreshLayout refreshlayout) {
                    if (listener != null) {
                        listener.onRefresh(refreshlayout);
                    }
                }
            });
        }
    }

    /**
     * 只使用SmartRefreshLayout的下拉刷新功能,加载更多功能使用BaseRecycerViewHelper来实现
     */
    public interface OnPullRefreshListener {
        void onRefresh(RefreshLayout refreshlayout);
    }
}
